'use strict';

const Controller = require('egg').Controller;

class BaseController extends Controller {
  get user() {
    return this.ctx.state.user;
  }

  success(data = null, message = 'success') {
    this.ctx.body = {
      code: 200,
      data,
      message,
    };
  }

  error(message = 'error', code = 500) {
    this.ctx.body = {
      code,
      message,
      data: null,
    };
  }
}

module.exports = BaseController; 